package com.app.mingluxing.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.baidu.mapapi.search.core.PoiInfo;


import java.util.List;

/**
 * Created by Aaron on 15/8/26.
 */
public class LocationAdapter extends BaseAdapter {

    private Context ctx;
    private List<PoiInfo> allPoi;

    public LocationAdapter(Context ctx, List<PoiInfo> allPoi) {
        this.ctx = ctx;
        this.allPoi = allPoi;

    }

    public void setAllPoi(List<PoiInfo> allPoi) {
        this.allPoi = allPoi;
    }

    @Override
    public int getCount() {
        return allPoi.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_location_layout, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_loaction_name = (TextView) convertView.findViewById(R.id.tv_loaction_name);
            viewHolder.tv_loaction_address = (TextView) convertView.findViewById(R.id.tv_loaction_address);
            convertView.setTag(viewHolder);

        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }

        viewHolder.tv_loaction_name.setText(allPoi.get(position).name);
        viewHolder.tv_loaction_address.setText(allPoi.get(position).address);

        return convertView;
    }

    private class ViewHolder {
        private TextView tv_loaction_name;
        private TextView tv_loaction_address;
    }

}
